package com.xfly.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.view.TitleBarView;

import java.util.HashMap;
import java.util.Map;

public class AddBankActivity extends BaseMvpActivity
{
    TitleBarView title_bar;

    EditText editckr,kh,phone,khaddress,bankname;

    TextView enter,tozc;

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_addbank);
    }

    @Override
    public void initViews() {
        title_bar = findViewById(R.id.title_bar);
        kh = findViewById(R.id.kh);
        phone = findViewById(R.id.phone);
        enter = findViewById(R.id.enter);
        khaddress = findViewById(R.id.khaddress);
        bankname = findViewById(R.id.bankname);
        editckr = findViewById(R.id.ckr);
        tozc = findViewById(R.id.tozc);

        title_bar.setText("新增银行卡");
    }

    @Override
    public void initEvents() {
        title_bar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
        tozc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getContext(),BankList2Activity.class));
            }
        });
        enter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                add();
            }
        });
    }

    private void add(){
        Map<String,String> map = new HashMap<>();
        map.put("bank_card",kh.getText().toString());
        map.put("name",editckr.getText().toString());
        map.put("bank_phone",phone.getText().toString());
        map.put("bank_address",khaddress.getText().toString());
        map.put("bank",bankname.getText().toString());
        apiDataRepository.addbank(map, new ApiNetResponse<Object>() {
            @Override
            public void onSuccess(Object data) {
                showMsg("添加成功");
                finish();
            }
        });
    }
}
